-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: _JSXStyle is not defined #716
Conversation
`addDefault` only accepts a `nameHint` and doesn't guarantee the name of the resulting default import. The identifier returned by `addDefault` should be referenced. This change renames the default import hint to `_JSXStyleImport`, and adds a variable declaration after the import to assign the default import to `_JSXStyle`. As a result, instead of this being output in some cases: ```js import _JSXStyle2 from 'styled-jsx/style'; ``` This will be output: ```js import _JSXStyleImport2 from 'styled-jsx/style'; var _JSXStyle = _JSXStyleImport2; ```
var _JSXStyle = _style.default;␊ | ||
␊ | ||
function Test() {␊ | ||
return <div>␊ | ||
<_style.default id={_App.default.__hash}>{_App.default}</_style.default>␊ | ||
<_JSXStyle id={_App.default.__hash}>{_App.default}</_JSXStyle>␊ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pretty much explains what's going on.
Using `node.body.splice` broke tests for external CSS.
Hi @morrisallison thank you for taking the time to look into this. It seems that the problem right now is that When @jaydenseric introduced this change I anticipated this issue: #684 (comment) If we want to fix this, we will have to generate the identifier (the name of the import specifier) upfront when we enter the Please let me know if I misunderstood the issue that you are trying to fix. |
Yup, that's accurate 👍🏽 However, I didn't want to do a lot of refactoring to reference the identifier everywhere. This change is intended to be quick (maybe dirty) fix to unblock. A proper fix will be more involved like you described. |
I'd rather fix this properly. We need to create the import identifier when we https://github.com/vercel/styled-jsx/blob/master/src/_utils.js#L383 |
Closing, because I don't have the bandwidth to work on further changes, but I'm glad this could help identify the problem and solution. |
Description
addDefault
only accepts anameHint
and doesn't guarantee the name of the resulting default import. The identifier returned byaddDefault
should be referenced.This change renames the default import hint to
_JSXStyleImport
, and adds a variable declaration after the import to assign the default import to_JSXStyle
.As a result, instead of this being output in some cases:
This will be output:
Admittedly, a better solution would be to use a named export like in #690, but this is quick fix that should unblock those who are having issues with later releases.
Related
Fixes #695
Fixes #696
Fixes #711